<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="D:\authine\h3bpm10.7\sunlord\src\main\webapp\Cluster\assets\javascripts\jquery.js" language="JavaScript" charset="UTF-8"></script>
    <script >
        function convertText() {

            console.log("111...........");
            //html
            var text1 =  $("#convertText").val();
            var $jsp = $("<div>"+text1.trim()+"</div>");
            //找到所有 SheetLabel
            var $spans = $jsp.find("span[data-type='SheetLabel'],label[data-type='SheetLabel'],span[class='mybt']");
            if($spans.length==0) {
                alert("未找到label");
                return false;
            }

            //json
            var strJson = $("#convertJson").val();

            var jsonObj = null;
            if(strJson && strJson.trim()){
                jsonObj = JSON.parse(strJson);
            }else{
                jsonObj = new Object();
            }

            var dataObj = new Object();

            for (var i = 0; i < $spans.length; i++) {
                var $label = $($spans[i]);
                var datafield = $label.attr("data-datafield");

               var languages = jsonObj[datafield];

               if(languages){
                   $.each(languages,function (key,val) {
                       if(val  && $label.text() ){
                           $label.attr(key,val);
                       }
                   })
               }

               if($label.text())
                     dataObj[datafield]=$label.text();


            }
            if(jsonObj)
                $("#isCode").text($jsp.html());


            $("#getdatas").text(JSON.stringify(dataObj));

        }


    </script>


</head>
<body>



<div style="text-align: center;" >
    json:<textarea   id="convertJson"  style="width: 500px;height: 200px;"> </textarea>
    <br/>
    html: <textarea   id="convertText"  style="width: 500px;height: 200px;"> </textarea>
    <br/>
    <input type="button"  onclick="convertText()" value="确定">
</div>


<div>
    <span> 结果：</span>
    <code id="isCode" style="width: 500px;height: 200px">


    </code>

</div>

<div>
    <span> 数据项：</span>
    <code id="getdatas" style="width: 500px;height: 200px">


    </code>

</div>





</body>
</html>